import math

def is_prime(num):
    if num <= 1:
        return False
    for i in range(2, int(math.sqrt(num)) + 1):
        if num % i == 0:
            return False
    return True

def find_closest_prime(num):
    closest_prime = num
    diff = 0

    while True:
        if is_prime(closest_prime - diff):
            return closest_prime - diff
        if is_prime(closest_prime + diff):
            return closest_prime + diff
        diff += 1

def main():
    numbers_dict = {
        "zero": 0,
        "one": 1,
        "two": 2,
        "three": 3,
        "four": 4,
        "five": 5,
        "six": 6,
        "seven": 7,
        "eight": 8,
        "nine": 9
    }

    input_str = input()
    words = input_str.split()

    if len(words) != 3 or any(word not in numbers_dict for word in words):
        print("Wrong input")
        return

    num = numbers_dict[words[0]] * 100 + numbers_dict[words[1]] * 10 + numbers_dict[words[2]]

    if num >= 100 and num <= 999:
        closest_prime = find_closest_prime(num)
        print(closest_prime)
    else:
        print("Wrong input")

if __name__ == "__main__":
    main()
